<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<%@include file="../../common/mastertop.jsp"%>
<p class="page-title">
	<i class="locale-icon"></i> <span>当前位置 : </span> <span
		class="cur-page-title">用户列表</span> <span>· 权限设置</span>
</p>


<div class="form-inline clearfix" id="seachform">
<input type="hidden" id="roleId" value="${model.roleId}" />
	<div class="filter-warp rect-fff clearfix">
		<div class="form-group col-xs-12">
			<span class="form-label">角色名称：${model.role.roleName}</span>
		</div>
	</div>

	<div class="rect-fff table-warp clearfix">
		<div class="table-scroll">
			<table id="users">
				<tr>
					<th style="text-align: left">一级菜单</th>
					<th style="text-align: left">二级菜单</th>
				</tr>

				<c:forEach items="${model.items}" var="item" varStatus="itemStatus">
				<tr>
					<td style="text-align: left"><c:if
							test="${item.menuId1!=null}">
						<label class="checkbox" style="padding-left:5px"> <input name="menu1"
																				 type="checkbox"
						<c:if test="${item.select1==1}">
																				 checked="checked"
						</c:if>
																				 level="1"
																				 menuid="${item.menuId1}" id="menuId_${item.menuId1}"
																				 onclick="javascript:selectMenu2(this,'${item.menuId1}')"
																				 value="${item.menuId1}"> ${item.menuId1Name}
						</label>
					</c:if></td>
					<td style="text-align: left"><c:if
							test="${item.menuId2!=null}">
						<label class="checkbox"> <input name="menu2_${item.parentId}"
														type="checkbox"
						<c:if test="${item.select2==1}">
														checked="checked"
						</c:if>
														level="1"
														menuid="${item.menuId2}" id="menuId_${item.menuId2}"
														value="${item.menuId2}"> ${item.menuId2Name}
						</label>
					</c:if></td>
					</c:forEach>


			</table>
		</div>


	</div>
	<div class="form-horizontal pt-15  form-clean-magin" style="padding-bottom:20px">
       <div class="form-group text-center">
		<button type="button" class="runmi-btn runmi-primary"
			onclick="selectall()">全选</button>
		<button type="button" class="runmi-btn runmi-sure-btn"
			onclick="save()">保存</button>
	</div>
	</div>

</div>


<script type="text/javascript">
  function selectMenu2(obj,id){
	  if ($(obj).prop("checked")) {
		  $("input[name='menu2_"+ id +"']").prop("checked",true);
	  }else{
		  $("input[name='menu2_"+ id +"']").prop("checked",false);
	  }
	 
  }
  function selectall() {	 
	    $("#users :checkbox").attr("checked", true);   
	    //checkCount();
	}	
    var postData;
	function save(){
		// alert('save');
		postData="roleId=" + $('#roleId').val();
		var flag=false;
		$("#users tbody tr input").each(function () {
			var id=$(this).attr('id');
			var name=$(this).attr('name');
			var value=$(this).val();
			var level=$(this).attr('level');
			if ($(this).prop("checked")) {
			 	//alert(id + " name:" +  name + " value:" +value)
				if(level=='1'){
					//选择一级菜单
					postData=postData + "&menuId1s=" + value;
					flag=true;
				}
				if(level=='2'){
					//选择二级菜单
					postData=postData + "&menuId2s=" + value;
					flag=true;
				}
			}			
		});
		if(flag){
			sendOpTo(postData);
		}
	}
	function sendOpTo(){
		//alert(postData);
		layer.load(1, {shade: [0.5,'#fff']});
		
		 $.ajax({
	            type: "POST",
	            url: "configSave",
	            data: postData,
	            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	            async: true, // 同步  true 异步。默认是异步
	            dataType: 'json',
	            error: function(resultdata) {
	            	layer.closeAll();
	            },
	            success: function(resultdata) {
	            	layer.closeAll();
	                if(resultdata.returnCode=="0000"){               	
	                	layer.alert('操作成功',{icon: 1}, function(){
	                		layer.closeAll();
	                	 	 oksubmit();
	                	});
	                }else{
	                	layer.alert(resultdata.returnMessage);
	                }
	            }
	        });
	}
	
    function editReturn() {
       layer.closeAll();
       oksubmit();
    }
    function closeAll() {
        layer.closeAll();
     }
    function edit(id){
		var domainUrl="edit?roleId=" + id;
		
		 $('#wrap').hide();
	     $('#editFrame').attr("src", domainUrl);
	     $('#edit').show(); 
	}
	function reset(userId){
		var postData="userId=" + userId;
		 $.ajax({
	            type: "POST",
	            url: "resetPassword",
	            data: postData,
	            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	            async: true, // 同步  true 异步。默认是异步
	            dataType: 'json',
	            error: function(resultdata) {
	            	layer.closeAll();
	            },
	            success: function(resultdata) {
	            	layer.closeAll();
	                if(resultdata.returnCode=="0000"){               	
	                	layer.alert('操作成功',{icon: 1}, function(){
	                		layer.closeAll();
	                	 	 oksubmit();
	                	});
	                }else{
	                	layer.alert(resultdata.returnMessage);
	                }
	            }
	        });
	}
	</script>
<%@include file="../../common/masterbottom.jsp"%>
